<?php
require_once "ByteBuffer.php";
require_once "DataUtil.php";
require_once "UtilHash.php";
class DataArea{
	private $Description;
	private $SecretCode;
	function __construct(){
		$this->SecretCode = unpack('C*', UtilHash::generateKey( 32 )  ) ;
	}
	static function swap($bytebuffer){
		$area = new DataArea();
		$area->Description = DataUtil::readSBin( $bytebuffer ) ;
		$area->SecretCode = DataUtil::readBBin( $bytebuffer ) ;
		return $area;
	}
	function getDescription(){
		return implode(array_map("chr",  $this->Description )) ;
	}
	function setDescription($description){
		$this->Description = unpack('C*', $description ) ;
	}
	function getSecretCode(){
		return implode(array_map("chr",  $this->SecretCode )) ;
	}
	function getBinSize(){
		$size = 0;
		$size += 2  + count($this->Description);
		$size += 1  + count($this->SecretCode);
		return $size;
	}
	function getBinary(){
		$buf = ByteBuffer::allocate( $this->getBinSize() ) ;
		DataUtil::writeSBin( $buf , $this->Description ) ;
		DataUtil::writeBBin( $buf , $this->SecretCode ) ;
		return  $buf ->_array() ;
	}
}
?>